package com.xunwulian.web.entity;

import com.xunwulian.base.constant.PkgType;
import com.xunwulian.base.entity.CardInfoEntity;
import com.xunwulian.base.entity.CardNodeEntity;
import com.xunwulian.base.util.DateStyle;
import com.xunwulian.base.util.DateUtil;
import com.xunwulian.base.util.EnumUtils;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;

/**
 * 卡信息Entity
 *
 * @author liyankai
 */
public class CardNodeEntityWrapper extends CardNodeEntity {

    private String pkgStr;

    private String userPkgStr;

    private String openDateStr;

    private String userOpenDateStr;

    private String endDateStr;

    private String userEndDateStr;

    public CardNodeEntityWrapper() {
    }

    public CardNodeEntityWrapper(CardInfoEntity entity) {
        try {
            ConvertUtils.register(new DateConverter(null), java.util.Date.class);
            BeanUtils.copyProperties(this, entity);
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 用户套餐
        this.pkgStr = PkgType.UNKNOWN.getDesc();
        PkgType pkgType = EnumUtils.getTripEnumByType(PkgType.class, this.getPkg());
        if (pkgType != null) {
            pkgStr = pkgType.getDesc();
        }

        // 用户套餐
        this.userPkgStr = PkgType.UNKNOWN.getDesc();
        PkgType userPkgType = EnumUtils.getTripEnumByType(PkgType.class, this.getUserPkg());
        if (userPkgType != null) {
            userPkgStr = userPkgType.getDesc();
        }

        this.openDateStr = getOpenDate() == null ? "" : DateUtil.DateToString(getOpenDate(), DateStyle.YYYY_MM_DD);
        this.userOpenDateStr = getUserOpenDate() == null ? "" : DateUtil.DateToString(getUserOpenDate(), DateStyle.YYYY_MM_DD);

    }


    public CardNodeEntityWrapper(CardNodeEntity entity) {
        try {
            ConvertUtils.register(new DateConverter(null), java.util.Date.class);
            BeanUtils.copyProperties(this, entity);
        } catch (Exception e) {
            e.printStackTrace();
        }

        // 用户套餐
        this.pkgStr = PkgType.UNKNOWN.getDesc();
        PkgType pkgType = EnumUtils.getTripEnumByType(PkgType.class, this.getPkg());
        if (pkgType != null) {
            pkgStr = pkgType.getDesc();
        }

        // 用户套餐
        this.userPkgStr = PkgType.UNKNOWN.getDesc();
        PkgType userPkgType = EnumUtils.getTripEnumByType(PkgType.class, this.getUserPkg());
        if (userPkgType != null) {
            userPkgStr = userPkgType.getDesc();
        }

        this.openDateStr = getOpenDate() == null ? "" : DateUtil.DateToString(getOpenDate(), DateStyle.YYYY_MM_DD);
        this.userOpenDateStr = getUserOpenDate() == null ? "" : DateUtil.DateToString(getUserOpenDate(), DateStyle.YYYY_MM_DD);

    }

    public String getPkgStr() {
        return pkgStr;
    }

    public void setPkgStr(String pkgStr) {
        this.pkgStr = pkgStr;
    }

    public String getOpenDateStr() {
        return openDateStr;
    }

    public void setOpenDateStr(String openDateStr) {
        this.openDateStr = openDateStr;
    }

    public String getEndDateStr() {
        return endDateStr;
    }

    public void setEndDateStr(String endDateStr) {
        this.endDateStr = endDateStr;
    }

    public String getUserOpenDateStr() {
        return userOpenDateStr;
    }

    public void setUserOpenDateStr(String userOpenDateStr) {
        this.userOpenDateStr = userOpenDateStr;
    }

    public String getUserEndDateStr() {
        return userEndDateStr;
    }

    public void setUserEndDateStr(String userEndDateStr) {
        this.userEndDateStr = userEndDateStr;
    }

    public String getUserPkgStr() {
        return userPkgStr;
    }

    public void setUserPkgStr(String userPkgStr) {
        this.userPkgStr = userPkgStr;
    }
}
